package com.wyd.common.util;

import java.util.Calendar;
import java.util.Date;

/**
 * 时间相关工具
 */
public class DateUtils {
    private DateUtils() {}

    /**
     * 获取当年的开始时间
     * ****-01-01 00:00:00:000
     */
    public static Date getYearStartTime(int year) {
        Calendar calendar = Calendar.getInstance(); // 获取当前日期
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, Calendar.JANUARY);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        return calendar.getTime();
    }

    /**
     * 获取当年的结束时间
     * ****-12-31 23:59:59:999
     */
    public static Date getYearEndTime(int year) {
        Calendar calendar = Calendar.getInstance(); // 获取当前日期
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, Calendar.DECEMBER);
        calendar.set(Calendar.DAY_OF_MONTH, 31);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);

        return calendar.getTime();
    }
}
